package com.app.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.drawable.AnimationDrawable;
import android.widget.TextView;

import lib.common.R;


public class DialogLoading_sina
{

	private static Dialog progress = null;
	
	 
	
	static public void showLoadingDialog(final Activity activity) {
		
		if ((progress != null) &&progress.isShowing()) {
			return;
		}
		
		
		
	/*	
		progress = new ProgressDialog(activity, R.style.FullTransparentStyle);
		progress.setProgressStyle(Progressdialog.STYLE_SPINNER);
		progress.show();
	*/	
		progress = new Dialog(activity, R.style.Theme_FullTransparentStyle); 
		progress.setContentView(R.layout.dialog_loading_sina);
		progress.setCanceledOnTouchOutside(true);
		TextView tv_animation =(TextView)progress.findViewById(R.id.tv_animation);
		tv_animation.setBackgroundResource(R.anim.loading);
		AnimationDrawable frameAnimation = (AnimationDrawable) tv_animation.getBackground();
		frameAnimation.start();
		
		
		
		progress.show();

		///*
		progress.setOnDismissListener( new OnDismissListener() {
			
			@Override
			public void onDismiss(DialogInterface dialog) {
				// TODO Auto-generated method stub
			
				/*
				if( Utils1.isConnectInternet(activity) == false)
					activity.finish();
					*/
			}
		});
		//*/
		
	} 
	
	
	
	
	/**
	 * 隐藏加载对话框
	 */
	static public void dismissLoadingDialog() {
		if (progress != null) {
			progress.dismiss();
		}
	}


 
	static public void show(final Context activity) {
		
		if ((progress != null) &&progress.isShowing()) {
			return;
		}
		
		progress = new Dialog(activity, R.style.Theme_FullTransparentStyle); 
		progress.setContentView(R.layout.dialog_loading_sina);
		progress.setCanceledOnTouchOutside(true);
		TextView tv_animation =(TextView)progress.findViewById(R.id.tv_animation);
		tv_animation.setBackgroundResource(R.anim.loading);
		AnimationDrawable frameAnimation = (AnimationDrawable) tv_animation.getBackground();
		frameAnimation.start();
		
		
		progress.show();

		///*
		progress.setOnDismissListener( new OnDismissListener() {
			
			@Override
			public void onDismiss(DialogInterface dialog) {
				// TODO Auto-generated method stub
			
				/*
				if( Utils1.isConnectInternet(activity) == false)
					activity.finish();
					*/
			}
		});
		//*/
		
	} 
	
	
	
	
	/**
	 * 隐藏加载对话框
	 */
	static public void dismiss() {
		if (progress != null) {
			progress.dismiss();
		}
	}
	
	
	
}